import datetime
import os
import shutil
import cv2

paths = R'D:\project\python\changeFileName\data\video'
save_path = R'D:\project\python\changeFileName\data\images'
def dismant(path:str,name:str):
    # print(path,name)
    curren_path = name.split(".")[0]
    os.mkdir(save_path+"/"+curren_path)

    vc = cv2.VideoCapture(path+"/"+name)
    ret,frame = vc.read()
    index = 0
    while ret:
            cv2.imshow('some',frame)
            cv2.waitKey(1)
            time = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
            if index % 20 == 0:
                # print(save_path+'/'+ curren_path +"/"+time+ "_" + str(index)+'.jpg')
                
                print(save_path+'/'+ curren_path+"/"+  str(time) +str(index)+'.jpg')
                cv2.imwrite(save_path+'/'+ curren_path+"/"+ str(time)+"_" + str(index)+'.jpg',frame)
            ret,frame = vc.read()
            index = index + 1

def getAllVideo(path:str):
    # dismant(paths)
    files = os.listdir(path)
    for file in files:
        dismant(path,file)

if __name__ == "__main__":
    if  os.path.exists(save_path):
        shutil.rmtree(save_path)
    os.mkdir(save_path)
    getAllVideo(paths)
    